package com.bite.demo.service;

import com.bite.demo.mapper.BlogInfoMapper;
import com.bite.demo.model.BlogInfo;
import com.bite.demo.model.PageResult;
import com.bite.demo.model.RequestPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogService {
    @Autowired
    private BlogInfoMapper blogInfoMapper;


    public List<BlogInfo> getList() {
        return blogInfoMapper.selectAll();
    }

    public BlogInfo getBlogDetail(Integer blogId) {
        return blogInfoMapper.selectById(blogId);
    }

    public Integer insertBlog(BlogInfo blogInfo) {
        return blogInfoMapper.insertBlog(blogInfo);
    }

    public Integer updateBlog(BlogInfo blogInfo) {
        return blogInfoMapper.updateBlog(blogInfo);
    }


    public PageResult<BlogInfo> getListByPage(RequestPage requestPage) {
        Integer count = blogInfoMapper.count();

        List<BlogInfo> blogInfos = blogInfoMapper.selectAllByPage(requestPage.getOffset(),requestPage.getPageSize());

        return new PageResult<>(blogInfos,count,requestPage);




    }
}
